package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.AdminOperation;
import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.iapPlatform.IapPlatformDTO;
import com.etone.smartAudit.enums.IapDataField;
import com.etone.smartAudit.service.IapPlatformService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.iapPlatform.IapPlatformDetailVO;
import com.etone.smartAudit.vo.iapPlatform.IapPlatformListVO;
import com.etone.smartAudit.vo.iapPlatform.IapPlatformSimpleVO;
import com.etone.smartAudit.vo.iapPlatform.IapPlatformTotalVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-06-16 19:52:35
 * @Description 系统平台
 */
@RestController
@AllArgsConstructor
@Api(tags = "系统平台", value = "IapPlatformController")
public class IapPlatformController {

    private IapPlatformService iapPlatformService;

    @ApiOperation(value = "系统平台信息列表")
    @GetMapping("/iapPlatforms")
    public PagerVO<IapPlatformListVO> list(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "系统名称") @RequestParam(required = false) String name,
            @ApiParam(value = "分类") @RequestParam(required = false) IapDataField dataField
    ) {
        return iapPlatformService.list(name, dataField, page, pageSize);
    }

    @ApiOperation(value = "查询系统名称是否存在")
    @GetMapping("/iapPlatforms/name/exists")
    public Boolean checkNameExists(
            @ApiParam(value = "系统id(编辑时判断是否是自身)") @RequestParam(required = false) Integer id,
            @ApiParam(value = "系统名称", required = true) @RequestParam String name
    ) {
        return iapPlatformService.checkNameExists(id, name);
    }

    @ApiOperation(value = "系统平台总数")
    @GetMapping("/iapPlatforms/dataField/total")
    public List<IapPlatformTotalVO> findIapPlatformsDataFieldTotal() {
        return iapPlatformService.findIapPlatformsDataFieldTotal();
    }

    @ApiOperation(value = "系统平台基本信息列表")
    @GetMapping("/iapPlatforms/simple")
    public PagerVO<IapPlatformSimpleVO> listSimple(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "关键字(名称)") @RequestParam(required = false) String keys
    ) {
        return iapPlatformService.listSimple(keys, page, pageSize);
    }

    @AdminOperation(module = "系统信息查询", item = "添加")
    @ApiOperation(value = "添加系统信息")
    @PostMapping("/iapPlatforms")
    public void add(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "系统信息表单") @RequestBody IapPlatformDTO iapPlatformDTO
    ) {
        iapPlatformService.save(null, iapPlatformDTO, admin);
    }

    @AdminOperation(module = "系统信息查询", item = "编辑")
    @ApiOperation(value = "编辑系统信息")
    @PutMapping("/iapPlatforms/{id}")
    public void edit(
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "系统信息表单") @RequestBody IapPlatformDTO iapPlatformDTO
    ) {
        iapPlatformService.save(id, iapPlatformDTO, admin);
    }

    @ApiOperation(value = "系统信息详情")
    @GetMapping("/iapPlatforms/{id}")
    public IapPlatformDetailVO detail(
            @ApiParam(value = "id", required = true) @PathVariable Integer id
    ) {
        return iapPlatformService.detail(id);
    }

    @AdminOperation(module = "系统信息查询", item = "删除")
    @ApiOperation(value = "删除系统信息")
    @DeleteMapping("/iapPlatforms/{id}")
    public void delete(
            @ApiParam(value = "id", required = true) @PathVariable Integer id
    ) {
        iapPlatformService.delete(id);
    }

    @AdminOperation(module = "系统信息查询", item = "批量删除")
    @ApiOperation(value = "删除系统信息")
    @DeleteMapping("/iapPlatforms/batch/{ids}")
    public void batchDelete(@ApiParam(value = "ids", required = true) @PathVariable List<Integer> ids) {
        iapPlatformService.batchDelete(ids);
    }
}
